home *** CD-ROM | disk | FTP | other *** search
- #include <dos.h>
- #include <string.h>
- #include <alloc.h>
- #include "drvrfunc.h"
- #include "filefunc.h"
-
- char *dirMemErr = "Unable to allocate enough memory for directory";
-
- /*************************************************************************
- * FUNCTION: INITFILELIST - Initializes linked list that filenames are
- * to be stored in.
- *
- * Inputs: *ptr - Head pointer to linked list.
- * lines - Number of lines that will be displayed in the windows.
- *
- * Output: none
- *************************************************************************/
- void InitFileList(FILEPTR *ptr, int lines)
- {
- int i;
-
- ptr->active = NULL;
-
- ptr->start = ptr->stop = ptr->current = ptr->head;
- for(i = 0; (i < (lines - 1)) && (ptr->stop->next != NULL); i++)
- ptr->stop = ptr->stop->next;
- }
-
- /*************************************************************************
- * FUNCTION: GETFILELIST - Builds linked list of sorted filenames.
- *
- * Inputs: **files - Head pointer to linked list.
- * *pathName - Path and extension of files to add to linked list.
- *
- * Output: OK if no error, MEMERR if process runs out of memory.
- *************************************************************************/
- int GetFileList(FILELEMENT **files, char *pathName)
- {
- struct find_t fileInfo;
- FILELEMENT *entry;
-
- if(_dos_findfirst(pathName, _A_NORMAL, &fileInfo) == OK)
- if((entry = (FILELEMENT *)malloc(sizeof(FILELEMENT))) != NULL)
- {
- strcpy(entry->filename, fileInfo.name);
- PadBlanks(entry->filename, 12);
- entry->status = STOPPED;
- Add(files, entry);
- }
- else
- return(MEMERR);
- else
- return(FILERR);
-
- while(_dos_findnext(&fileInfo) == OK)
- {
- if((entry = (FILELEMENT *)malloc(sizeof(FILELEMENT))) != NULL)
- {
- strcpy(entry->filename, fileInfo.name);
- PadBlanks(entry->filename, 12);
- entry->status = STOPPED;
- Add(files, entry);
- }
- else
- return(MEMERR);
- }
- return(OK);
- }
-
- /*************************************************************************
- * FUNCTION: ADD - Adds an element to a linked list.
- *
- * Inputs: **fileList - Pointer to linked list.
- * *newEntry - Element to add.
- *
- * Output: none
- *************************************************************************/
- void Add(FILELEMENT **fileList, FILELEMENT *newEntry)
- {
- int found = NO;
- int test;
- char tempStr[13];
- FILELEMENT *files = *fileList;
-
- if(files != NULL)
- {
- while(found == NO)
- {
- test = strcmpi(files->filename, newEntry->filename);
- if(test == 0)
- found = YES;
- else
- if(test > 0)
- {
- newEntry->prev = files->prev;
- if(files->prev == NULL)
- {
- newEntry->next = *fileList;
- files->prev = newEntry;
- *fileList = newEntry;
- }
- else
- {
- newEntry->next = files;
- files->prev->next = newEntry;
- files->prev = newEntry;
- }
- found = YES;
- }
- else
- {
- if(files->next != NULL)
- files = files->next;
- else
- {
- newEntry->prev = files;
- newEntry->next = NULL;
- files->next = newEntry;
- found = YES;
- }
- }
- }
- }
- else
- {
- *fileList = newEntry;
- newEntry->prev = NULL;
- newEntry->next = NULL;
- }
- }
-
- /*************************************************************************
- * FUNCTION: PADBLANKS - Right pad string with blanks.
- *
- * Inputs: string - String to pad.
- * size - Total number of characters in string (including blanks).
- *
- * Output: none
- *************************************************************************/
- void PadBlanks(char string[], int size)
- {
- int i;
-
- for(i = strlen(string); i < size; i++)
- string[i] = ' ';
- string[size] = 0;
- }
-
- /*************************************************************************
- * FUNCTION: FINDFILETYPE - Returns file type of a given filename.
- *
- * Inputs: filename - Filename to analyze.
- *
- * Output: File type.
- *************************************************************************/
- int FindFileType(char filename[])
- {
- int i = 0;
- int length = strlen(filename);
-
- for(i = 0; (i < length) && (filename[i] != '.'); i++);
- if(i != length)
- switch(filename[i + 1])
- {
- case 'M':
- return(Midi);
- case 'C':
- return(FM);
- case 'V':
- return(DskVoice);
- }
- return(FILERR);
- }
-
-